package service

import (
	sqlc "bgs/db/sqlc"
	"bgs/util"
	"context"
)

// LoggingAccountParam 记录门店账户变动日志参数
type LoggingAccountParam struct {
	StoreID  int64
	BrandID  int64
	IsIn     bool
	Category sqlc.EmStoreAccountLogCategory
	Amount   int64
	Subject  string
	ExtInfo  string
}

// LoggingAccount 记录门店账户变动日志
func (s *StoreServiceImp) loggingAccount(ctx context.Context, q *sqlc.Queries, p LoggingAccountParam) (err error) {
	slog := util.NewContextLogger(ctx, s.slog)
	_, err = q.CreateStoreAccountLog(ctx, sqlc.CreateStoreAccountLogParams{
		StoreID:   p.StoreID,
		BrandID:  sqlc.NInt64FromInt64(p.BrandID),
		IsIn:     p.IsIn,
		Category: string(p.Category),
		Amount:   util.Int64IfThenElse(p.IsIn, 1, -1) * p.Amount,
		Subject:  p.Subject,
		ExtInfo:  p.ExtInfo,
	})
	if err != nil {
		return
	}
	slog.Infof("创建门店账户变动日志 ok")
	return
}
